package com.hyl.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description TODO
 * @Author hyl
 * @Date 2023/5/10 9:54
 **/
@Controller
public class UserController  {

	//只能通过get方式提交
	@GetMapping("/login1") // http://localhost:8080/SpringMVC_ch09_war_exploded/login
	protected ModelAndView login1(HttpServletRequest request) throws Exception {
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		Integer pwd1= Integer.valueOf(pwd);

		System.out.println("login"+name);
		ModelAndView tmp = new ModelAndView();
		tmp.setViewName("index"); // 经过处理==>转发==> /jsp/index.jsp
		tmp.addObject("age","18"); //数据存储到request
		return tmp;
	}

	//只能通过get方式提交
	@GetMapping("/login")
	protected ModelAndView login(String name ,Integer pwd ) throws Exception {
		System.out.println("login:"+name);
		ModelAndView tmp = new ModelAndView();
		tmp.setViewName("index"); // 经过处理==>转发==> /jsp/index.jsp
		tmp.addObject("age","18"); //数据存储到request
		return tmp;
	}

	//只能通过post方式提交
	@PostMapping("/reg") //http://localhost:8080/SpringMVC_ch09_war_exploded/reg
	protected ModelAndView reg() throws Exception {
		System.out.println("注册");
		ModelAndView tmp = new ModelAndView();
		tmp.setViewName("index"); // 经过处理==>转发==> /jsp/index.jsp
		tmp.addObject("age","18"); //数据存储到request
		return tmp;
	}

	//任意提交方式都可以
	@RequestMapping("/logout") //http://localhost:8080/SpringMVC_ch09_war_exploded/logout
	protected ModelAndView logout() throws Exception {
		System.out.println("注销");
		ModelAndView tmp = new ModelAndView();
		tmp.setViewName("index"); // 经过处理==>转发==> /jsp/index.jsp
		tmp.addObject("age","18"); //数据存储到request
		return tmp;
	}


}
